[%# The contents of this file are subject to the Mozilla Public
  # License Version 1.1 (the "License"); you may not use this file
  # except in compliance with the License. You may obtain a copy of
  # the License at http://www.mozilla.org/MPL/
  #
  # Software distributed under the License is distributed on an "AS
  # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  # implied. See the License for the specific language governing
  # rights and limitations under the License.
  #
  # The Original Code is the Bugzilla Bug Tracking System.
  #
  # The Initial Developer of the Original Code is Netscape Communications
  # Corporation. Portions created by Netscape are
  # Copyright (C) 1998 Netscape Communications Corporation. All
  # Rights Reserved.
  #
  # Contributor(s): Myk Melez <myk@mozilla.org>
  #%]

[% PROCESS global/variables.none.tmpl %]
[% USE CGI %]
[%  
    # We use a query string rietveldreview=true to indicate when in rietveld mode. 
    rietveldReview = CGI.param('rietveldreview')
%]

<link href="skins/standard/global.css" rel="stylesheet" type="text/css">
<link href="skins/custom/global.css" rel="stylesheet" type="text/css">
<style>
* { font-size: small; }
#comment { width: 100%; height: 100%; font-family: monospace; }
#form-controls { height: 40px; }
#form-controls td { width: 25%; text-align: center; }
</style>

<script type="text/javascript">
  <!--
  var viewing_formatted_diff = true;
  function viewPrettyPatch()
    {
      viewing_formatted_diff = !viewing_formatted_diff;
      var src = "attachment.cgi?id=[% attachment.id %]";
      var buttonText = "View Formatted Diff";
      if (viewing_formatted_diff) {
        src += "&action=prettypatch"
        buttonText = "View Plain Diff";
      }

      top.document.getElementById('viewFrame').src = src;
      document.getElementById('viewPrettyPatchButton').innerHTML = buttonText;
    }
    function onSubmitComments()
    {
[% IF rietveldReview %]
         var submitBtn = document.getElementById('submitBtn');
         submitBtn.innerHTML = 'Fetching comments from Rietveld...';
         submitBtn.disabled = true; // Disable since this is asynch.
         top.getComments();
         // Handle the error case of Rietveld not responding by giving
         // the user another chance.
         setTimeout(function() {
             submitBtn.innerHTML = 'Fetching comments timed out ... retry?';
             submitBtn.disabled = false;
         }, 30000);
         return false;
[% ELSE %]
         // If someone just left the entire comment alone, then upload the form
         // with no comment at all.
         var textarea = document.getElementById("comment");
         if (textarea.defaultValue === textarea.value)
             textarea.value = "";
         return true;
[% END %]
    }
  //-->
</script>

<form method="post" action="attachment.cgi" target="_top" onsubmit="return onSubmitComments();">
  <input type="hidden" name="id" value="[% attachment.id %]">
  <input type="hidden" name="action" value="update">
  <input type="hidden" name="contenttypemethod" value="manual">
  <input type="hidden" name="delta_ts" value="[% attachment.modification_time FILTER html %]">
  [% IF user.id %]
    <input type="hidden" name="token" value="[% issue_hash_token([attachment.id, attachment.modification_time]) FILTER html %]">
  [% END %]
  <input type="hidden" name="description" value="[% attachment.description FILTER html %]">
  <input type="hidden" name="filename" value="[% attachment.filename FILTER html %]">
  <input type="hidden" name="contenttypeentry" value="[% attachment.contenttype FILTER html %]">
  <input type="hidden" name="ispatch" [% IF attachment.ispatch %] value="1" [% ELSE %] value="0" [% END %] >
  <input type="hidden" name="isobsolete" [% IF attachment.isobsolete %] value="1" [% ELSE %] value="0" [% END %] >
  [% IF (Param("insidergroup") && user.in_group(Param("insidergroup"))) %]
    <input type="hidden" name="isprivate" [% IF attachment.isprivate %] value="1" [% ELSE %] value="0" [% END %] >
  [% END %]

<table style="width:100%; height:90%" cellpadding=0 cellspacing=0>
<tr id="form-controls">
<td>
    <button id="submitBtn" type="submit">Submit</button>
</td>
<td>
    [% IF flag_types.size > 0 %]
      [% PROCESS "flag/list.html.tmpl" bug_id=attachment.bug_id attach_id=attachment.id %]<br>
    [% END %]
</td>
<td>
[% IF attachment.ispatch %]
    <table>
    <tr><th style="text-align: left;">Bot Status:</th></tr>
    <tr>
    <td>
      <div class="statusBubble" style="margin-left: 30px;">
        <iframe src="https://webkit-queues.appspot.com/status-bubble/[% attachment.id %]"
                style="width: 400px; height: 20px; border: none;" scrolling="no">
        </iframe>
      </div>
    </td>
    </tr>
    </table>
[% END %]
</td>
<td>
    <div>Back to <a href="show_bug.cgi?id=[% attachment.bug_id %]" target="_top">[% terms.Bug %] #[% attachment.bug_id %]</a></div>
[% IF attachment.ispatch %]
    <script type="text/javascript">
    <!--
        if (typeof document.getElementById == "function") {
          document.write('<p><button type="button" id="viewPrettyPatchButton" onclick="viewPrettyPatch();">View Plain Diff</button></p>');
        }
    //-->
    </script>
[% END %]
</td>
</tr>
<tr>
<td colspan="4">
[% IF rietveldReview %]
Enter high-level comments below.  Make detailed comments above.  Submit will submit both.<br>
[% ELSE %]
Enter comments below:<br>
[% END %]
<textarea id=comment name="comment" wrap="soft">
[% IF !rietveldReview %]
[% quotedpatch FILTER html %]
[% END %]
</textarea><br>

</tr>
</table>

</form>
